package com.huawei.hmsdemo10086;

import android.app.Application;

import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.huawei.hms.common.util.Logger;
import com.huawei.hms.videokit.player.InitFactoryCallback;
import com.huawei.hms.videokit.player.WisePlayerFactory;
import com.huawei.hms.videokit.player.WisePlayerFactoryOptionsExt;

public class VideoKitApplication  extends Application {
    private static final String TAG = "VideoKitApplication";
    private static WisePlayerFactory factory;

    @Override
    public void onCreate() {
        super.onCreate();


        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        SDKInitializer.initialize(this);
        //自4.3.0起，百度地图SDK所有接口均支持百度坐标和国测局坐标，用此方法设置您使用的坐标类型.
        //包括BD09LL和GCJ02两种坐标，默认是BD09LL坐标。
        SDKInitializer.setCoordType(CoordType.BD09LL);

        // setDeviceId方法需要传入手机的DeviceId
        // setServeCountry方法需要传入国家/地区码
        WisePlayerFactoryOptionsExt factoryOptions =
                new WisePlayerFactoryOptionsExt.Builder().setDeviceId("xxx").build();
        // Application onCreate在多进程的场景下会被调用多次
        // App需要在App进程（App包名）和播放器进程（App包名:player）的Application onCreate中调用WisePlayerFactory.initFactory()接口
        WisePlayerFactory.initFactory(this, factoryOptions, new InitFactoryCallback() {
            @Override
            public void onSuccess(WisePlayerFactory wisePlayerFactory) {
                Logger.d(TAG, "onSuccess wisePlayerFactory:" + wisePlayerFactory);
                factory = wisePlayerFactory;
            }

            @Override
            public void onFailure(int errorCode, String msg) {
                Logger.e(TAG, "onFailure errorcode:" + errorCode + " reason:" + msg);
            }
        });
    }

    public static WisePlayerFactory getWisePlayerFactory() {
        return factory;
    }
}
